/**
 * 
 */
package com.the9tcat.everydayapp.data;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * @author jianhpin
 * 
 */
public class Common {

	public static final String ACTION_SYNC_SUCCEED = "com.the9tcat.dailyapp.action_sync_succeed";

	public static final String[] GENDER = { "不限", "男", "女" };

	public static final int BABY = 0x00000001;
	public static final int CHILD = 0x00000010;
	public static final int YOUNG = 0x00000100;
	public static final int ADULT = 0x00001000;
	public static final int OLD = 0x00010000;

	public static String stringFromStream(InputStream is) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(is));
		StringBuffer sb = new StringBuffer();
		String line = "";
		while ((line = reader.readLine()) != null) {
			sb.append(line);
			sb.append("\n");
		}
		return sb.toString();
	}

	public static Bitmap bitmapFromUrl(String url) throws MalformedURLException, IOException {
		HttpURLConnection huc = (HttpURLConnection) new URL(url)
				.openConnection();
		InputStream is = huc.getInputStream();
		Bitmap b = BitmapFactory.decodeStream(is);
		return b;
	}
}
